import { useModel } from "umi";
import compress from "gql-compress";

const useCheckStaffPhone = () => {
    const { graphqlFetch } = useModel("global");

    const checkStaffPhone = async ({ osPhon, notEqualTo }) => {
        let res = await graphqlFetch({
            query: notEqualTo ? queryNotEqualTo : query,
            variables: { osPhon, notEqualTo },
        });
        return res ? res.a.totalCount : null;
    };

    return { checkStaffPhone };
};

let query = compress(`query MyQuery($osPhon: String!) {
    a: allOrganizationStaffs(condition: { osPhon: $osPhon }) {
        totalCount
    }
}`);

let queryNotEqualTo = compress(`query MyQuery($osPhon: String!, $notEqualTo: UUID!) {
    a: allOrganizationStaffs(condition: { osPhon: $osPhon }, filter: { osUuid: { notEqualTo: $notEqualTo } }) {
        totalCount
    }
}`);

export default useCheckStaffPhone;
